 

type ElementType = Element & {attachEvent:any,removeEventListener:any,detachEvent:any}

class BindEvent {
      public element:ElementType
      constructor(ele:ElementType){
              this.element = ele;
      }
      addEvenetListener = (Eventtype,handle)=>{
              if(this.element?.addEventListener){
                this.element.addEventListener(Eventtype,handle,false)  
              }else if(this.element?.attachEvent){
                this.element.attachEvent('on'+Eventtype,()=>{
                         handle.call(this.element);
                }); 
              }else{
                 this.element['on'+Eventtype] = handle; 
              }
              
      }
      removeEventListener = (Eventtype,handle)=>{
              if(this.element?.removeEventListener){
                this.element?.removeEventListener(Eventtype,handle,false)
              }else if(this.element?.detachEvent){
                const element = this.element;
                this.element.detachEvent('on'+type,handle)
              }else{
                this.element['on'+Eventtype] = null;  
              } 
      }
    //   阻止时间冒泡
        stopPropagation = (e)=>{
           if(e.stopPropagation){
            e.stopPropagation()
           }else{
            e.cancelBubble = true;
           }
      }
    //   取消默认时间事件
        preventDefault = (e)=>{
        if(e.stopPropagation){
        e.preventDefault();
        }else{
        e.returnValue = true;
        }
      }
      getTarget = ()=>this.element
}
export default BindEvent